package com.ruoyi.system.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.entity.Room;
import com.ruoyi.system.mapper.RoomMapper;
import com.ruoyi.system.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/room")
public class RoomController extends BaseController {

    @Autowired
    private IRoomService roomService;
    @Autowired
    private RoomMapper roomMapper;

    @Log(title = "用户管理", businessType = BusinessType.INSERT)//历史操作审计
    @GetMapping("/list")
    public AjaxResult list(Room room) {
        List<Room> list = roomService.list(Wrappers.query(room));
        return AjaxResult.success(list);
    }

    @Log(title = "用户管理", businessType = BusinessType.INSERT)//历史操作审计
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Long id) {
        Room room = roomService.getWithElders(id);
        return AjaxResult.success(room);
    }

    @PostMapping
    public AjaxResult add(@RequestBody Room room) {
        roomService.save(room);
        return AjaxResult.success();
    }

    @PutMapping
    public AjaxResult edit(@RequestBody Room room) {
        roomService.updateById(room);
        return AjaxResult.success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        //roomService.removeById(id);
        roomMapper.deleteById(id);
        return AjaxResult.success();
    }
}